import os
import mybook
#import config


def ux_suffix(path):
    """
    Type_dict = {
    "py"     : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_PY),
    "pyw"    : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_PY),
    "pyi"    : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_PY),
    "go"     : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_GO),
    "lua"    : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_LUA),
    "rs"     : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_RUST),
    "config" : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_CONF),
    "conf"   : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_CONF),
    "yaml"   : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_YAML),
    "yml"    : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_YAML),
    "json"   : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_JSON),
    "css"    : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_CSS),
    "html"   : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_HTML),
    "xml"    : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_XML),
    "ui"     : (config.BOOK.M_PROGRAMME_CLASS, config.TEXT_TYPE_XML),
    "xls"    : (config.BOOK.M_TABLE_CLASS, config.TEXT_TYPE_XLSX),
    "xlsx"   : (config.BOOK.M_TABLE_CLASS, config.TEXT_TYPE_XLSX),
    "csv"    : (config.BOOK.M_TABLE_CLASS, config.TEXT_TYPE_CSV),
    "mp3"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_MP3),
    "mp4"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_MP4),
    "wav"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_WAV),
    "wma"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_WMA),
    "flac"   : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_FLAC),
    "ts"     : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_TS),
    "aac"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_AAC),
    "avi"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_AVI),
    "flv"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_FLV),
    "m4a"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_M4A),
    "mpeg"   : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_MPEG),
    "mpg"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_MPE),
    "ogg"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_OGG),
    "mov"    : (config.BOOK.M_MEDIA_CLASS, config.MEDIA_TYPE_MOV),
    "jpeg"   : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_JPEG),
    "jpg"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_JPEG),
    "png"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_PNG),
    "bmp"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_BMP),
    "gif"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_GIF),
    "ico"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_ICO),
    "pcx"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_PCX),
    "pnm"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_PNM),
    "tiff"   : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_TIFF),
    "tga"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_TGA),
    "xpm"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_XPM),
    "cur"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_CUR),
    "ani"    : (config.BOOK.M_IMAGE_CLASS, config.IMAGE_TYPE_ANI),
    }
    """

    name = os.path.basename(path)
    res = mybook.Type_dict(name.split(".")[1])
    if res:
        return res
    s = open(path, "r", encoding="utf-8")
    try:
        s.read(1)
    except UnicodeDecodeError:
        res = mybook.BOOK.M_NULL_CLASS
    else:
        res = mybook.BOOK.M_TEXT_CLASS 
    finally:
        s.close()
    return (res, mybook.TYPE_NULL)